<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生成绩管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
            padding: 20px;
        }

        .container {
            max-width: 1000px;
            margin: 0 auto;
            background: white;
            border-radius: 8px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            padding: 30px;
        }

        h1 {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 2px solid #eee;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        thead {
            background-color: #3498db;
            color: white;
        }

        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }

        th {
            font-weight: 600;
        }

        tbody tr:hover {
            background-color: #f1f9ff;
        }

        tbody tr:nth-child(even) {
            background-color: #f9f9f9;
        }

        tbody tr:nth-child(even):hover {
            background-color: #f1f9ff;
        }

        .action-btn {
            display: inline-block;
            background-color: #3498db;
            color: white;
            text-decoration: none;
            padding: 12px 25px;
            border-radius: 6px;
            font-weight: 500;
            transition: all 0.3s ease;
            margin-top: 20px;
            border: none;
            cursor: pointer;
            text-align: center;
        }

        .action-btn:hover {
            background-color: #2980b9;
            transform: translateY(-2px);
            box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
        }

        .footer {
            text-align: center;
            margin-top: 30px;
            color: #7f8c8d;
            font-size: 14px;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 2px solid #f0f0f0;
        }

        .message-container {
            position: fixed;
            top: 20px;
            left: 0;
            right: 0;
            display: flex;
            justify-content: center;
            z-index: 1000;
            animation: fadeIn 0.3s ease-in-out;
        }

        .message-alert {
            padding: 15px 20px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            gap: 10px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            max-width: 80%;
            min-width: 300px;
        }

        .message-alert.success {
            background-color: #d4edda;
            color: #155724;
            border-left: 5px solid #28a745;
        }

        .message-alert.info {
            background-color: #d1ecf1;
            color: #0c5460;
            border-left: 5px solid #17a2b8;
        }

        .message-alert i {
            font-size: 1.2em;
        }

        .close-btn {
            background: none;
            border: none;
            color: inherit;
            cursor: pointer;
            margin-left: auto;
            padding: 0;
            opacity: 0.7;
            transition: opacity 0.2s;
        }

        .close-btn:hover {
            opacity: 1;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }
    </style>
    <!-- 添加Font Awesome图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
</head>
<body>
<div class="container">

    <div th:if="${param.error}" class="message-container">
        <div class="message-alert info">
            <i class="fas fa-info-circle"></i>
            <span th:text="${param.error}"></span>
            <button class="close-btn" onclick="this.parentElement.style.display='none'">
                <i class="fas fa-times"></i>
            </button>
        </div>
    </div>

    <div th:if="${message}" class="message-container">
        <div class="message-alert" th:classappend="${#strings.startsWith(message, '成功')} ? 'success' : 'info'">
            <i class="fas" th:classappend="${#strings.startsWith(message, '成功')} ? 'fa-check-circle' : 'fa-info-circle'"></i>
            <span th:text="${message}"></span>
            <button class="close-btn" onclick="this.parentElement.style.display='none'">
                <i class="fas fa-times"></i>
            </button>
        </div>
    </div>

    <div class="header">
        <div>
            <h1>学生成绩管理系统</h1>
            <p style="color: #7f8c8d; font-size: 14px; margin-top: 5px;">
                欢迎，<span th:text="${session.currentUser.name}"></span>
            </p>
        </div>
        <div>
            <a href="/students" class="action-btn">
                <i class="fas fa-home"></i> 返回主界面
            </a>
            <a href="/logout" class="action-btn" style="background-color: #7f8c8d; margin-left: 10px;">
                <i class="fas fa-sign-out-alt"></i> 登出
            </a>
        </div>
    </div>

    <!-- 添加新增成绩的表单 -->
    <form action="/scores" method="post">
        <input type="hidden" name="student_id" th:value="${studentId}">
        <input type="text" name="score" placeholder="成绩" required>
        <input type="text" name="course" placeholder="课程名称" required>
        <button type="submit" class="action-btn">
            <i class="fas fa-plus"></i> 添加成绩
        </button>
    </form>

    <table>
        <thead>
        <tr>
            <th>学号</th>
            <th>成绩</th>
            <th>课程名称</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="score : ${scores}">
            <td th:text="${studentId}"></td>  <!-- 直接显示当前学生ID -->
            <td th:text="${score.score}"></td>
            <td>
                <a th:href="@{/courses/{coursename}(coursename=${score.course}, studentId=${studentId})}"
                   th:text="${score.course}"></a>
            </td>
            <!--<td th:text="${score.course}"></td>-->
            <td>
                <!-- 添加删除按钮 -->
                <form th:action="@{/scores/{id}(id=${score.id})}" method="post" style="display: inline;">
                    <input type="hidden" name="_method" value="delete">
                    <input type="hidden" name="studentId" th:value="${studentId}">
                    <button type="submit" class="action-btn" style="background-color: #e74c3c;">
                        <i class="fas fa-trash"></i> 删除
                    </button>
                </form>
            </td>
        </tr>
        </tbody>
    </table>

    <div class="footer">
        © 2023 学生成绩管理系统 | 数据更新时间: <span th:text="${#dates.format(#dates.createNow(), 'yyyy-MM-dd HH:mm')}"></span>
    </div>
</div>
</body>
</html>